package com.yuantong.xyerp.core.provider.dao;

import com.yuantong.xyerp.core.api.model.Transportation;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 运输信息 Mapper 接口
 * </p>
 *
 * @author JianguoYin
 * @since 2021-07-21
 */
public interface TransportationMapper {


    @Select({"<script> " +
            "SELECT * FROM t_transportation t " +
            "WHERE 1=1 " +
            "<if test=\"startTime != null\"> " +
            "  AND t.create_time &gt;= #{startTime} " +
            "</if>" +
            "<if test=\"endTime != null\"> " +
            "  AND t.create_time &lt;= #{endTime} " +
            "</if> " +
            "<if test=\"fuzzy != null and fuzzy != ''\"> " +
            "<bind name=\"bindKey\" value=\"'%'+fuzzy+'%'\"/> " +
            "   AND (t.car_no LIKE #{bindKey} OR t.name LIKE #{bindKey} OR t.mobile LIKE #{bindKey}) " +
            "</if> " +
            "<if test=\"ids != null and ids.size() > 0\"> " +
            "   AND t.id IN " +
            "<foreach collection=\"ids\" item=\"id\" open=\"(\" close=\")\" separator=\",\"> " +
            "#{id} " +
            "</foreach> " +
            "</if> " +
            "ORDER BY t.create_time DESC " +
            "</script>"})
    @ResultMap("BaseResultMap")
    List<Transportation> findByFuzzy(Date startTime, Date endTime, String fuzzy, List<String> ids);
}
